<?php
set_time_limit(0);
dl("php_sdl.dll");

define('APP_TITLE', '11 - Image scaling');

// Start SDL engine with VIDEO submodule
if(SDL_Init(SDL_INIT_VIDEO|SDL_INIT_AUDIO) < 0) {
	trigger_error('SDL can not be initialized. Exiting.');
	exit(1);
}

// Create a Window of 640x480, 16 bits of depth
$video = SDL_SetVideoMode(640, 480, 16, SDL_HWSURFACE);
if(is_null($video)) {
	trigger_error('Unable to create a new Window with the desired arguments.');
	exit(1);
}

SDL_WM_SetCaption(APP_TITLE, APP_TITLE);

// Load a BMP image from filesystem
$img = SDL_LoadBMP('agent.bmp');
if(is_null($img)) {
	trigger_error('Unable to load the specified image.');
	exit(1);
}

$img = gfx_rotozoomSurface($img['handle'], 45, 3, 1);

// Put the image on memory on the screen buffer
SDL_BlitSurface($img, null, $video, null);

// Refresh the whole screen
SDL_flip($video);

$event = null;
while(SDL_WaitEvent(&$event)) {
	if($event['type'] == SDL_QUIT) break;
}

// Free resources
SDL_FreeSurface($img);

// Stop SDL engine
SDL_Quit();

?>
